#!/usr/bin/env python3
# coding=utf-8

import os
import argparse
import compare
import find_ecu_pkg
import compare

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--src', type=str, default=None)
    parser.add_argument('--bin', type=str, default=None)
    args = parser.parse_args()

    src = args.src
    bin = args.bin

    if src is not None and bin is not None:
        files = find_ecu_pkg.find_ecu_pkg(src)

        for f in files:
            file = f['file']
            name = f['name']

            binfile = os.path.join(bin, name + '.bin')
            if not os.path.exists(binfile):
                print('error:', binfile + ' not found.', file)
            else:
                if name.endswith('hex'):
                    compare.compare_hex(file, binfile)
                elif name.endswith('s19'):
                    compare.compare_s19(file, binfile)
                else:
                    print('error:', 'invalid file: ' + flie)

            print('---------------------------------------------------\n')

    else:
        print('error:', src, bin)

